﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using SERP.StringMappings;
using SERP.DAO;
using SERP.Controllers;
namespace SERP.Modules.PersonTypes{
	public partial class PersonTypesInputFields : SERP.Modules.ModuleBase
	{
		protected void Page_Load(object sender, EventArgs e){
			LoadLanguage();
		}
		private PersonTypesEntity model=new PersonTypesEntity();
		public PersonTypesEntity Model{
			set{
				model=value;
			}
			get{
				return model;
			}
		}
		//Load All lable text
		private void LoadLanguage(){
			labelPersonTypeId.Text=PersonTypesStringMapping.PersonTypeId+":";
			validRQPersonTypeId.ErrorMessage=SERP.Constants.APP_REQUIRE_WARNING;		
			validExpressionPersonTypeId.ErrorMessage=SERP.Constants.APP_REQUIRE_INTERGER_WARNING;			
			validCustomPersonTypeIdExists.ErrorMessage=SERP.Constants.APP_EXIST_WARNING;
			labelTypeName.Text=PersonTypesStringMapping.TypeName+":";
			labelNote.Text=PersonTypesStringMapping.Note+":";
		}   
		public void UpdateToModel(){
			model.PersonTypeId=Convert.ToInt32(txtPersonTypeId.Text);
			model.TypeName=Convert.ToString(txtTypeName.Text);
			model.Note=Convert.ToString(txtNote.Text);
		}
		public void UpdateToScreen(){
			txtPersonTypeId.Text=Convert.ToString(model.PersonTypeId);
			txtTypeName.Text=model.TypeName;
			txtNote.Text=model.Note;
		}
		public void ClearScreen(){
			txtPersonTypeId.Text="0";
			txtTypeName.Text="";
			txtNote.Text="";
		}
		//Check if exists PersonTypeId
		private bool CheckExistsPersonTypeId(){	
			bool existsPersonTypeId=false;		
			decimal dValue=0;
			decimal.TryParse(txtPersonTypeId.Text,out dValue);
			existsPersonTypeId=PersonTypesController.CheckExistsPersonTypeId(dValue);
			return existsPersonTypeId;					 
		}
		protected void validCustomPersonTypeIdExists_ServerValidate(object source, ServerValidateEventArgs args)
		{
			args.IsValid=!CheckExistsPersonTypeId();
		}
		public bool ValidateScreen(){
			bool result=true;
			return result;
		}	
	}
}
